package com.cskaoyan.service;

import com.cskaoyan.bean.ListData;
import com.cskaoyan.bean.Log;
import com.cskaoyan.bean.LogExample;
import com.cskaoyan.mapper.LogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author heyyon
 */
@Service
public class AdminLogServiceImpl implements AdminLogService{
    @Autowired
    LogMapper logMapper;
    @Override
    public ListData<Log> list(Integer page, Integer limit, String sort, String order) {
        PageHelper.startPage(page, limit);
        LogExample logExample = new LogExample();
        logExample.setOrderByClause(sort + " " + order);
        List<Log> logList = logMapper.selectByExample(logExample);
        ListData<Log> listData=new ListData<>();
        PageInfo<Log> logPageInfo = new PageInfo<>(logList);
        long total=logPageInfo.getTotal();
        listData.setItems(logList);
        listData.setTotal((int) total);
        return listData;
    }
}
